package com.ap.core.domain;

import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;

import com.ap.core.common.types.InputMessageType;
import com.ap.core.common.types.MessageStatus;
import com.ap.core.common.types.TransactionChannelType;
import com.ap.core.common.types.TransactionRestrictionType;
import com.ap.core.cxf.jaxb.common.DeliveryType;
import com.ap.core.cxf.jaxb.paymentdetails.TxnStatusType;
import com.ap.core.cxf.jaxb.rtp.TransactionCheckOutType;
import com.ap.core.cxf.jaxb.rtp.TransactionType;

/**
 * User: Ranjit.Singh
 */
@Entity
@Table(name = "T_ORDER_PAYMENT")
@AttributeOverride(name = "id",column = @Column(name = "ap_txn_id"))
@TypeDef(name = "id", typeClass = String.class)
@NamedQueries({
		@NamedQuery(name="updateOrderPaymentMessageStatus", query="UPDATE OrderPayment op SET op.statusCode = :messageStatus, op.statusTimeStmp = :statusTimeStmp, op.lastUpdateTimestmp = :lastUpdateTimestmp, op.confirmationExpiryTimeStmp = :confirmationExpiryTimeStmp WHERE op.id= :id"),
		@NamedQuery(name="updateOrderPayment", query="UPDATE OrderPayment op SET op.statusCode = :messageStatus, op.zappConsumerId = :zappConsumerId, op.fiId = :fiId, op.statusTimeStmp = :statusTimeStmp, op.lastUpdateTimestmp = :lastUpdateTimestmp, op.apMessageId = :apMessageId, op.fiCustomerId=:fiCustomerId , op.confirmationExpiryTimeStmp = :confirmationExpiryTimeStmp WHERE op.id= :id"),
        @NamedQuery(name="updateOrderPaymentOnConfirmation", query="UPDATE OrderPayment op SET op.statusCode = :messageStatus, op.debitAccountNumber = :debitAccountNumber, op.debitSortCode = :debitSortCode , op.transactionStatus = :transactionStatus, op.paymentDescTimeStamp = :paymentDescTimeStamp, op.fasterPaymentRef = :fasterPaymentRef, op.statusTimeStmp = :statusTimeStmp, op.lastUpdateTimestmp = :lastUpdateTimestmp, op.rollNumber = :rollNumber, op.apMessageId = :apMessageId, op.confirmationTimeStmp = :confirmationTimeStmp, op.transactionStatusCode = :transactionStatusCode WHERE op.id = :id")

})
public class OrderPayment extends Identifiable<String> {

    public LocalDateTime getPaymentDescTimeStamp() {
		return paymentDescTimeStamp;
	}

	private static final long serialVersionUID = -747892374897239847L;
    
    @Column(name = "ap_txn_retrieval_id")
    private Long apTransactionRetrievalId;

    @Column(name = "RTP_ID")
    private String rtpId;

    @Column(name = "msg_id")
    private Long apMessageId;

    @Column(name = "RECONCILIATION_CYCLE_ID")
    private String reconciliationCycleId;

    @Column(name = "TRANSACTION_CHANNEL_CODE")
    @Enumerated(EnumType.STRING)
    private TransactionChannelType transactionChannelType;

    @Column(name = "MESSAGE_TYPE_CODE")
    @Enumerated(EnumType.STRING)
    private InputMessageType inputMessageType;

    @Column(name = "DISTRIBUTOR_ID")
    private Long distributorId;

    @Column(name = "MERCHANT_ID")
    private Long merchantId;

    @Column(name = "TRANSACTION_TYPE")
    @Enumerated(EnumType.STRING)
    private TransactionType transactionType;

    @Column(name = "transaction_checkout_type")
    @Enumerated(EnumType.STRING)
    private TransactionCheckOutType transactionCheckoutType;

    @Column(name = "TRANSACTION_RESTRICTION")
    @Enumerated(EnumType.STRING)
    private TransactionRestrictionType transactionRestrictionType;

    @Column(name = "INVOICE_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime invoiceTimeStmp;

    @Embedded
    @AttributeOverride(name = "value", column = @Column(name = "TOTAL_PAYMENT_REQUEST_AMOUNT"))
    private Amount totalPaymentRequestAmount;

    @Column(name = "CURRENCY_CODE")
    private String currencyCode;

    @Embedded
    @AttributeOverride(name = "accountNumber", column = @Column(name = "CREDIT_ACCOUNT_NUMBER"))
    private AccountNumber creditAccountNumber;

    @Embedded
    @AttributeOverride(name = "sortCode", column = @Column(name = "CREDIT_SORT_CODE"))
    private SortCode creditSortCode;

    @Column(name = "DELIVERY_TYPE_CODE")
    @Enumerated(EnumType.STRING)
    private DeliveryType deliveryType;

    @Column(name = "ADHOC_DELIVERY_INSTRUCTION")
    private String adhocDeliveryInstruction;

    @Column(name = "delivery_email_address")
    private String emailAddress;

    @Column(name = "STATUS_CODE")
    @Enumerated(EnumType.STRING)
    private MessageStatus statusCode;

    @Column(name = "STATUS_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime statusTimeStmp;

    @Column(name = "CREATION_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime creationTimeStmp;

    @Column(name = "last_update_tmstmp")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime lastUpdateTimestmp;

    @Column(name = "TRANSACTION_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime transactionTimeStmp;

    @Column(name = "RETRIEVAL_EXPIRY_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime retrievalExpiryTimeStmp;

    @Column(name = "ORDER_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime orderTimeStmp;

    @Column(name = "DEVICE_IP_ADDRESS")
    private String deviceIPAdress;

    @Column(name = "DEVICE_APPINTENT_ID")
    private Long deviceAppIntentId;

    @Column(name = "ZAPP_CONSUMER_ID")
    private Long zappConsumerId;

    @Column(name = "FI_ID")
    private Long fiId;
    
    @Embedded
    @AttributeOverride(name = "rollNumber", column = @Column(name = "DEBIT_ROLL_NUMBER"))
    private RollNumber rollNumber;

    @OneToMany(cascade = CascadeType.ALL , mappedBy = "apTransactionId")
    private List<OrderAmountDetail> orderAmountDetailList;

    @OneToOne(cascade = CascadeType.ALL, mappedBy = "orderPayment")
    private DeliveryAddress deliveryAddress;

    @OneToOne(cascade = CascadeType.ALL, mappedBy = "orderPayment")
    private MerchantAddress merchantAddress;

    @OneToMany(cascade = CascadeType.ALL , mappedBy = "apTransactionId")
    private List<OrderProductDetail> orderProductDetailList;

    @Embedded
    @AttributeOverride(name = "accountNumber", column = @Column(name = "DEBIT_ACCOUNT_NUMBER"))
    private AccountNumber debitAccountNumber;

    @Embedded
    @AttributeOverride(name = "sortCode", column = @Column(name = "DEBIT_SORT_CODE"))
    private SortCode debitSortCode;

   
    @Column(name = "fps_status_code")
    @Enumerated(EnumType.STRING)
    private TxnStatusType transactionStatus;
    
   
    @Column(name = "STATUS_REASON_CODE")
    private String transactionStatusCode;
    
    
    @Column(name = "PAYMENT_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime paymentDescTimeStamp;
    
    @Column(name = "FASTER_PAYMENT_REF_NUMBER")
    private String fasterPaymentRef;

    @Column(name = "latest_msg_id")
    private Long latestApMessageId;

    @Column(name = "reconciliation_date")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
    private LocalDate reconciliationDate;
    
    
    @Column(name = "FI_CUSTOMER_ID")
    private String fiCustomerId;

    @Transient
    private String appIntent;

    @Transient
    private String basketReferenceNumber;
    
    @Column(name = "RETRIEVAL_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime retrievalTimeStmp;
    
    @Column(name = "RECON_CUTOFF_END_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime reconCutoffEndTimeStmp;
    
    @Column(name = "CONFIRMATION_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime confirmationTimeStmp;
    
    @Column(name = "CONFIRMATION_EXPIRY_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime  confirmationExpiryTimeStmp;
	
    @Column(name = "MERCHANT_URL")
    private String merchantRedirectURL;


  

	private  OrderPayment(){

    }

    public OrderPayment(Long apMessageId, String apTransactionId, Long apTransactionRetrievalId,  LocalDateTime creationTimeStmp, String currencyCode,
                        DeliveryType deliveryType, Long deviceAppIntentId, Long distributorId, Long merchantId, InputMessageType inputMessageType,
                        String rtpId, String reconciliationCycleId, MessageStatus statusCode, LocalDateTime statusTimeStmp, Amount totalPaymentRequestAmount,
                        TransactionChannelType transactionChannelType, TransactionCheckOutType transactionCheckoutType, LocalDateTime transactionTimeStmp,
                        TransactionType transactionType, LocalDateTime orderTimeStmp, LocalDateTime lastUpdateTimestmp, LocalDate reconciliationDate,
                        LocalDateTime reconCutoffEndTimeStmp) {
        this.apMessageId = apMessageId;
        this.id = apTransactionId;
        this.apTransactionRetrievalId = apTransactionRetrievalId;
        this.creationTimeStmp = creationTimeStmp;
        this.currencyCode = currencyCode;
        this.deliveryType = deliveryType;
        this.deviceAppIntentId = deviceAppIntentId;
        this.distributorId = distributorId;
        this.merchantId = merchantId;
        this.rtpId = rtpId;
        this.reconciliationCycleId = reconciliationCycleId;
        this.statusCode = statusCode;
        this.statusTimeStmp = statusTimeStmp;
        this.totalPaymentRequestAmount = totalPaymentRequestAmount;
        this.transactionChannelType = transactionChannelType;
        this.transactionCheckoutType = transactionCheckoutType;
        this.transactionTimeStmp = transactionTimeStmp;
        this.transactionType = transactionType;
        this.orderTimeStmp = orderTimeStmp;
        this.lastUpdateTimestmp = lastUpdateTimestmp;
        this.reconciliationDate = reconciliationDate;
        this.inputMessageType = inputMessageType;
        this.reconCutoffEndTimeStmp = reconCutoffEndTimeStmp;
    }

    public void setOrderAmountDetailList(List<OrderAmountDetail> orderAmountDetailList) {
        this.orderAmountDetailList = orderAmountDetailList;
    }


    public void setAdhocDeliveryInstruction(String adhocDeliveryInstruction) {
        this.adhocDeliveryInstruction = adhocDeliveryInstruction;
    }

    public void setCreditAccountNumber(AccountNumber creditAccountNumber) {
        this.creditAccountNumber = creditAccountNumber;
    }

    public void setCreditSortCode(SortCode creditSortCode) {
        this.creditSortCode = creditSortCode;
    }

    public void setDeviceIPAdress(String deviceIPAdress) {
        this.deviceIPAdress = deviceIPAdress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public void setInvoiceTimeStmp(LocalDateTime invoiceTimeStmp) {
        this.invoiceTimeStmp = invoiceTimeStmp;
    }

    public void setStatusTimeStmp(LocalDateTime statusTimeStmp) {
        this.statusTimeStmp = statusTimeStmp;
    }

    public void setTransactionRestrictionType(TransactionRestrictionType transactionRestrictionType) {
        this.transactionRestrictionType = transactionRestrictionType;
    }

    public void setOrderProductDetailList(List<OrderProductDetail> orderProductDetailList) {
        this.orderProductDetailList = orderProductDetailList;
    }

    public InputMessageType getInputMessageType() {
        return inputMessageType;
    }

    public DeliveryAddress getDeliveryAddress() {
        return deliveryAddress;
    }

    public void setDeliveryAddress(DeliveryAddress deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public Long getLatestApMessageId() {
        return latestApMessageId;
    }

    public void setLatestApMessageId(Long latestApMessageId) {
        this.latestApMessageId = latestApMessageId;
    }

    public LocalDate getReconciliationDate() {
        return reconciliationDate;
    }

    public MerchantAddress getMerchantAddress() {
        return merchantAddress;
    }

    public void setMerchantAddress(MerchantAddress merchantAddress) {
        this.merchantAddress = merchantAddress;
    }

    public String getAppIntent() {
        return appIntent;
    }

    public void setAppIntent(String appIntent) {
        this.appIntent = appIntent;
    }

    public LocalDateTime getRetrievalExpiryTimeStmp() {
        return retrievalExpiryTimeStmp;
    }

    public void setRetrievalExpiryTimeStmp(LocalDateTime retrievalExpiryTimeStmp) {
        this.retrievalExpiryTimeStmp = retrievalExpiryTimeStmp;
    }

    public Long getZappConsumerId() {
        return zappConsumerId;
    }

    public void setZappConsumerId(Long zappConsumerId) {
        this.zappConsumerId = zappConsumerId;
    }

    public Long getFIId() {
        return fiId;
    }

    public void setFIId(Long fiId) {
        this.fiId = fiId;
    }

    public String getAdhocDeliveryInstruction() {
        return adhocDeliveryInstruction;
    }

    public Long getApMessageId() {
        return apMessageId;
    }

    public String getApTransactionId() {
        return getId();
    }
    
    public Long getApTransactionRetrievalId() {
        return apTransactionRetrievalId;
    }

    public LocalDateTime getCreationTimeStmp() {
        return creationTimeStmp;
    }

    public AccountNumber getCreditAccountNumber() {
        return creditAccountNumber;
    }

    public SortCode getCreditSortCode() {
        return creditSortCode;
    }

    public String getCurrencyCode() {
        return currencyCode;
    }

    public DeliveryType getDeliveryType() {
        return deliveryType;
    }

    public Long getDeviceAppIntentId() {
        return deviceAppIntentId;
    }

    public String getDeviceIPAdress() {
        return deviceIPAdress;
    }

    public Long getDistributorId() {
        return distributorId;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public LocalDateTime getInvoiceTimeStmp() {
        return invoiceTimeStmp;
    }

    public Long getMerchantId() {
        return merchantId;
    }

    public String getReconciliationCycleId() {
        return reconciliationCycleId;
    }

    public String getRtpId() {
        return rtpId;
    }

    public MessageStatus getStatusCode() {
        return statusCode;
    }

    public LocalDateTime getStatusTimeStmp() {
        return statusTimeStmp;
    }

    public Amount getTotalPaymentRequestAmount() {
        return totalPaymentRequestAmount;
    }

    public TransactionChannelType getTransactionChannelType() {
        return transactionChannelType;
    }

    public TransactionCheckOutType getTransactionCheckoutType() {
        return transactionCheckoutType;
    }

    public TransactionRestrictionType getTransactionRestrictionType() {
        return transactionRestrictionType;
    }

    public LocalDateTime getTransactionTimeStmp() {
        return transactionTimeStmp;
    }

    public TransactionType getTransactionType() {
        return transactionType;
    }

    public List<OrderAmountDetail> getOrderAmountDetailList() {
        return orderAmountDetailList;
    }

	public SortCode getDebitSortCode() {
		return debitSortCode;
	}

	public void setDebitSortCode(SortCode debitSortCode) {
		this.debitSortCode = debitSortCode;
	}

    public List<OrderProductDetail> getOrderProductDetailList() {
        return orderProductDetailList;
    }

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public AccountNumber getDebitAccountNumber() {
		return debitAccountNumber;
	}

	public void setDebitAccountNumber(AccountNumber debitAccountNumber) {
		this.debitAccountNumber = debitAccountNumber;
	}

	public TxnStatusType getTransactionStatus() {
		return transactionStatus;
	}

	public void setTransactionStatus(TxnStatusType transactionStatus) {
		this.transactionStatus = transactionStatus;
	}

	


	

	public String getFasterPaymentRef() {
		return fasterPaymentRef;
	}

	public void setFasterPaymentRef(String fasterPaymentRef) {
		this.fasterPaymentRef = fasterPaymentRef;
	}

	public RollNumber getRollNumber() {
		return rollNumber;
	}

	public void setRollNumber(RollNumber rollNumber) {
		this.rollNumber = rollNumber;
	}

    public LocalDateTime getOrderTimeStmp() {
        return orderTimeStmp;
    }

    public LocalDateTime getLastUpdateTimestmp() {
        return lastUpdateTimestmp;
    }

    public String getBasketReferenceNumber() {
        return basketReferenceNumber;
    }

    public void setBasketReferenceNumber(String basketReferenceNumber) {
        this.basketReferenceNumber = basketReferenceNumber;
    }

    public String getFiCustomerId() {
		return fiCustomerId;
	}

	public void setFiCustomerId(String fiCustomerId) {
		this.fiCustomerId = fiCustomerId;
	}
	
	public LocalDateTime getRetrievalTimeStmp() {
		return retrievalTimeStmp;
	}

	public void setRetrievalTimeStmp(LocalDateTime retrievalTimeStmp) {
		this.retrievalTimeStmp = retrievalTimeStmp;
	}
	
	public void setReconCutoffEndTimeStmp(LocalDateTime reconCutoffEndTimeStmp) {
		this.reconCutoffEndTimeStmp = reconCutoffEndTimeStmp;
	}

	public LocalDateTime getReconCutoffEndTimeStmp() {
		return reconCutoffEndTimeStmp;
	}


	public LocalDateTime getConfirmationTimeStmp() {
		return confirmationTimeStmp;
	}

	public LocalDateTime getConfirmationExpiryTimeStmp() {
		return confirmationExpiryTimeStmp;
	}

    public void setConfirmationExpiryTimeStmp(LocalDateTime confirmationExpiryTimeStmp) {
        this.confirmationExpiryTimeStmp = confirmationExpiryTimeStmp;
    }

    public void setConfirmationTimeStmp(LocalDateTime confirmationTimeStmp) {
        this.confirmationTimeStmp = confirmationTimeStmp;
    }

    public String getTransactionStatusCode() {
		return transactionStatusCode;
	}
	
	public String getMerchantRedirectURL() {
			return merchantRedirectURL;
	}

     public void setMerchantRedirectURL(String merchantRedirectURL) {
			this.merchantRedirectURL = merchantRedirectURL;
     }

	/* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
	@Override
	public String toString() {
		return "OrderPayment [apTransactionRetrievalId="
				+ apTransactionRetrievalId + ", rtpId=" + rtpId
				+ ", apMessageId=" + apMessageId + ", reconciliationCycleId="
				+ reconciliationCycleId + ", transactionChannelType="
				+ transactionChannelType + ", inputMessageType="
				+ inputMessageType + ", distributorId=" + distributorId
				+ ", merchantId=" + merchantId + ", transactionType="
				+ transactionType + ", transactionCheckoutType="
				+ transactionCheckoutType + ", transactionRestrictionType="
				+ transactionRestrictionType + ", invoiceTimeStmp="
				+ invoiceTimeStmp + ", totalPaymentRequestAmount="
				+ totalPaymentRequestAmount + ", currencyCode=" + currencyCode
				+ ", creditAccountNumber=" + creditAccountNumber
				+ ", creditSortCode=" + creditSortCode + ", deliveryType="
				+ deliveryType + ", adhocDeliveryInstruction="
				+ adhocDeliveryInstruction + ", emailAddress=" + emailAddress
				+ ", statusCode=" + statusCode + ", statusTimeStmp="
				+ statusTimeStmp + ", creationTimeStmp=" + creationTimeStmp
				+ ", lastUpdateTimestmp=" + lastUpdateTimestmp
				+ ", transactionTimeStmp=" + transactionTimeStmp
				+ ", expiryTimeStmp=" + retrievalExpiryTimeStmp + ", orderTimeStmp="
				+ orderTimeStmp + ", deviceIPAdress=" + deviceIPAdress
				+ ", deviceAppIntentId=" + deviceAppIntentId
				+ ", zappConsumerId=" + zappConsumerId + ", fiId=" + fiId
				+ ", rollNumber=" + rollNumber + ", orderAmountDetailList="
				+ orderAmountDetailList + ", deliveryAddress="
				+ deliveryAddress + ", merchantAddress=" + merchantAddress
				+ ", orderProductDetailList=" + orderProductDetailList
				+ ", debitAccountNumber=" + debitAccountNumber
				+ ", debitSortCode=" + debitSortCode + ", appIntent="
				+ appIntent + ", transactionStatus="
				+ transactionStatus + ", transactionStatusCode="
				+ transactionStatusCode + ", paymentDescTimeStamp=" + paymentDescTimeStamp
				+ ", fasterPaymentRef=" + fasterPaymentRef
				+ ", latestApMessageId=" + latestApMessageId
				+ ", reconciliationDate=" + reconciliationDate+ ", confirmationTimeStmp=" + confirmationTimeStmp + ", reconCutoffEndTimeStmp=" + reconCutoffEndTimeStmp+ ", fiCustomerId="+fiCustomerId + ", id=" + id
				+ "]";
	}
    
    
}
